Skip to content

Conversation

@Kludex
Copy link
Member

@Kludex Kludex commented Feb 3, 2026

Cute.

@Kludex Kludex requested a review from maxisbey February 3, 2026 09:54
@Kludex Kludex changed the title refactor: split RequestContext between server and client refactor: split RequestContext between server and client Feb 3, 2026
@claude
Copy link

claude bot commented Feb 3, 2026

Code Review

I found 3 issues that need attention:

Issue 1: Missing Migration Documentation

File: src/mcp/shared/context.py

This is a breaking change that requires migration documentation.

According to CLAUDE.md:

When making breaking changes, document them in docs/migration.md. Include:

  • What changed
  • Why it changed
  • How to migrate existing code

This PR changes the type signatures of RequestContext and Context classes:

  • RequestContext changed from Generic[SessionT, LifespanContextT, RequestT] to Generic[SessionT]
  • Context changed from Generic[ServerSessionT, LifespanContextT, RequestT] to Generic[LifespanContextT, RequestT]

Users with type annotations for tool/prompt/resource handlers or client callbacks will need to update their code:

  • Server side: Context[ServerSession, AppContext]Context[AppContext]
  • Client side: RequestContext[ClientSession, None]RequestContext[ClientSession]

Please add a section to docs/migration.md documenting this breaking change.

Issue 2: Missing Docstring for Public API

File: src/mcp/server/context.py (line 16)

The new public API class ServerRequestContext is missing a docstring.

According to CLAUDE.md:

Public APIs must have docstrings

Similar classes in the codebase have docstrings:

  • RequestContext: "Common context for handling incoming requests."
  • Context: Has extensive docstring explaining usage

Please add a docstring to ServerRequestContext explaining its purpose and usage. See the class definition here:

@dataclass(kw_only=True)
class ServerRequestContext(RequestContext[ServerSession], Generic[LifespanContextT, RequestT]):
lifespan_context: LifespanContextT
experimental: Experimental
request: RequestT | None = None

Issue 3: Incorrect Type Signature

File: tests/client/test_list_roots_callback.py (line 36)

The type signature Context[ServerSession] is incorrect after the refactor.

The Context class changed from Generic[ServerSessionT, LifespanContextT, RequestT] to Generic[LifespanContextT, RequestT]. The ServerSessionT parameter was removed.

Current (incorrect):

async def test_list_roots(context: Context[ServerSession], message: str):

The problem: ServerSession is now being used as LifespanContextT (the first type parameter), but ServerSession is a session type, not a lifespan context type. Since this test has no lifespan context, it should be:

async def test_list_roots(context: Context[None], message: str):

See the incorrect line here:

@server.tool("test_list_roots")
async def test_list_roots(context: Context[ServerSession], message: str):
roots = await context.session.list_roots()


async def default_elicitation_callback(
context: RequestContext[ClientSession, Any], # noqa: ARG001
context: RequestContext[ClientSession],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can have a ClientRequestContext.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea true, would be nice to have both

@Kludex Kludex merged commit b1f7eec into main Feb 3, 2026
34 checks passed
@Kludex Kludex deleted the refactor/separate-server-request-context branch February 3, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants